'use strict';

const Controller = require('../lib/controller');
const BMP24 = require('../lib/bmp24');

module.exports = class SecurityCodeController extends Controller {
  async index() {

    // Disable Browser cache
    this.ctx.set('Pragma', 'no-cache');
    this.ctx.set('Cache-Control', 'no-cache');

    // Call Generate Security Code Function
    this.ctx.set('Content-Type', 'image/bmp');

    if (!this.ctx.session.lbsSecurityCode) {
      this.ctx.genSecurityCode();
    }

    const bmp = new BMP24(100, 40);
    const str = this.ctx.session.lbsSecurityCode;
    bmp.drawStr(str, 10, 12, (255 << 16), 10);

    this.ctx.body = bmp.data;
  }

};
